<?php
namespace app\admin\controller;

class Category extends Admin{
    public function __construct(){
        parent::__construct();
        $this->model = 'Category';
        $this->assign("model",$this->model);
    }
    public function index(){
    	$wheredata = ['pid'=>0];
    	$this->assign("whereData",$wheredata);
    	return $this->fetch();
    }
    public function add(){
    	$menus_list = model("Category")->order("id")->select();
    	$menus_list = json_decode(json_encode($menus_list),true);
    	$Tree = new \base\tree\Tree;
        $menus = $Tree->toFormatTree($menus_list);
        $menus = array_merge([0 => ['id'=>0,'title_show'=>'顶级分类']], $menus);
        $this->assign('Menus', $menus);
    	return $this->fetch();
    }
    public function edit(){
    	$items = input("param.items");
        $db = model($this->model);
        $info = $db->get_data(['item_id' => $items]);
        $this->assign("info",$info);
    	
    	$menus_list = model("Category")->order("id")->select();
    	$menus_list = json_decode(json_encode($menus_list),true);
    	$Tree = new \base\tree\Tree;
        $menus = $Tree->toFormatTree($menus_list);
        $menus = array_merge([0 => ['id'=>0,'title_show'=>'顶级分类']], $menus);
        $this->assign('Menus', $menus);
    	return $this->fetch();
    }
}